In [1]:
from sympy import *
init_printing() #muestra símbolos más agradab
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import numpy as np
R=lambda n,d: Rational(n,d)

In [2]:
x,y,t=symbols('x,y,t')

PRACTICA 2

Ejercicio 1 a)

y=Function('y')(x) Ecuacion=Eq(y.diff(),-((x2-2*y2)/(x*y))) sol=dsolve(Ecuacion,y) Ecuacion,sol


In [3]:
z=Function('z')(x)
Ecuacionz=Eq(z.diff(),-(1-z**2)/(x*z))
solz=dsolve(Ecuacionz,z)
Ecuacionz,solz


Out[3]:
$$\left ( \frac{d}{d x} z{\left (x \right )} = \frac{z^{2}{\left (x \right )} - 1}{x z{\left (x \right )}}, \quad \left [ z{\left (x \right )} = - \sqrt{C_{1} x^{2} + 1}, \quad z{\left (x \right )} = \sqrt{C_{1} x^{2} + 1}\right ]\right )$$

Ejercicio 1 c)


In [4]:
y=Function('y')(x)
#Ecuacion=Eq(y.diff(),((3*(1+(y/x)**2)*atan(y/x))+y/x)/(x**2))
#sol=dsolve(Ecuacion,y)
#Ecuacion,sol

In [5]:
z=Function('z')(x)
Ecuacionz=Eq(z.diff(),3*(1+z**2)*atan(z)/x)
solz=dsolve(Ecuacionz,z)
Ecuacionz,solz


Out[5]:
$$\left ( \frac{d}{d x} z{\left (x \right )} = \frac{1}{x} \left(3 z^{2}{\left (x \right )} + 3\right) \operatorname{atan}{\left (z{\left (x \right )} \right )}, \quad z{\left (x \right )} = \tan{\left (C_{1} x^{3} \right )}\right )$$

Ejercicio 1 h)


In [6]:
y=Function('y')(x)
Ecuacion=Eq(y.diff(),(sqrt(x**2+y**2)/x))
#sol=dsolve(Ecuacion,y)
#Ecuacion,sol
Ecuacion


Out[6]:
$$\frac{d}{d x} y{\left (x \right )} = \frac{1}{x} \sqrt{x^{2} + y^{2}{\left (x \right )}}$$

In [14]:
z=Function('z')(x)
Ecuacionz=Eq(z.diff(),(sqrt(1+z**2)+z)**(-1)/x)
solz=dsolve(Ecuacionz,z)
Ecuacionz, solz


Out[14]:
$$\left ( \frac{d}{d x} z{\left (x \right )} = \frac{1}{x \left(\sqrt{z^{2}{\left (x \right )} + 1} + z{\left (x \right )}\right)}, \quad \frac{1}{2} \sqrt{z^{2}{\left (x \right )} + 1} z{\left (x \right )} + \frac{1}{2} z^{2}{\left (x \right )} - \log{\left (x \right )} + \frac{1}{2} \operatorname{asinh}{\left (z{\left (x \right )} \right )} = C_{1}\right )$$

In [15]:
solz.subs(z,x*y).simplify()


Out[15]:
$$C_{1} = \frac{x^{2}}{2} y^{2}{\left (x \right )} + \frac{x}{2} \sqrt{x^{2} y^{2}{\left (x \right )} + 1} y{\left (x \right )} - \log{\left (x \right )} + \frac{1}{2} \operatorname{asinh}{\left (x y{\left (x \right )} \right )}$$

In [ ]:

Ejercicio 1 ejer2 libro

supongamos $y_{0}=1$


In [16]:
x,y=symbols('x,y')
# Gráfica de ecuaciones implícitas
grafa=plot_implicit(Eq(x*y,0),show=False,aspect_ratio=(1,1))
for r in range(1,5):
    ecuaaux=plot_implicit(Eq(x**2+(y-1)**2,0.2*r**2),show=False,aspect_ratio=(1,1))
    grafa.append(ecuaaux[0])
for k in range(10):
    grafaaux=plot((-1)**k*k*x+1,(x,-5,5),show=False,aspect_ratio=(1,1))
    grafa.append(grafaaux[0])
grafa.show()


Ejercicio 1 ejer5 libro


In [17]:
y=Function('y')(x)
Ecuacion=Eq(y.diff(),(x+y+4)/(x-y-6))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[17]:
$$\left ( \frac{d}{d x} y{\left (x \right )} = \frac{x + y{\left (x \right )} + 4}{x - y{\left (x \right )} - 6}, \quad \log{\left (x - 1 \right )} = C_{1} - \log{\left (\sqrt{1 + \frac{\left(y{\left (x \right )} + 5\right)^{2}}{\left(x - 1\right)^{2}}} \right )} + \operatorname{atan}{\left (\frac{y{\left (x \right )} + 5}{x - 1} \right )}\right )$$

Ejercicio 2 ejer1 libro


In [18]:
y=Function('y')(x)
Ecuacion=Eq(y.diff(),-y*(x+2/y)**(-1))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[18]:
$$\left ( \frac{d}{d x} y{\left (x \right )} = - \frac{y{\left (x \right )}}{x + \frac{2}{y{\left (x \right )}}}, \quad y{\left (x \right )} = \frac{2}{x} \operatorname{LambertW}{\left (C_{1} x \right )}\right )$$

Ejercicio 2 ejer3 libro


In [19]:
y=Function('y')(x)
Ecuacion=Eq((x+y**3)*y.diff(),-(y-x**3))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[19]:
$$\left ( \left(x + y^{3}{\left (x \right )}\right) \frac{d}{d x} y{\left (x \right )} = x^{3} - y{\left (x \right )}, \quad \mathrm{False}\right )$$

Ejercicio 2 ejer5 libro


In [20]:
y=Function('y')(x)
Ecuacion=Eq(((x+x*cos(x*y)))*y.diff(),-(y+y*cos(x*y)))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[20]:
$$\left ( \left(x \cos{\left (x y{\left (x \right )} \right )} + x\right) \frac{d}{d x} y{\left (x \right )} = - y{\left (x \right )} \cos{\left (x y{\left (x \right )} \right )} - y{\left (x \right )}, \quad x y{\left (x \right )} + \left(\begin{cases} x & \text{for}\: y{\left (x \right )} = 0 \\\frac{\sin{\left (x y{\left (x \right )} \right )}}{y{\left (x \right )}} & \text{otherwise} \end{cases}\right) y{\left (x \right )} + \int^{y{\left (x \right )}} \begin{cases} x \cos{\left (y x \right )} - x & \text{for}\: y = 0 \\y \left(- y x \cos{\left (y x \right )} + \frac{1}{y^{2}} \sin{\left (y x \right )}\right) - y \sin{\left (y x \right )} + x \cos{\left (y x \right )} & \text{otherwise} \end{cases}\, dy = C_{1}\right )$$

Ejercicio 2 ejer7 libro


In [21]:
y=Function('y')(x)
Ecuacion=Eq(((sin(x)*sin(y)-x*exp(y)))*y.diff(),(exp(y)+cos(x)*cos(y))/1)
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[21]:
$$\left ( \left(- x e^{y{\left (x \right )}} + \sin{\left (x \right )} \sin{\left (y{\left (x \right )} \right )}\right) \frac{d}{d x} y{\left (x \right )} = e^{y{\left (x \right )}} + \cos{\left (x \right )} \cos{\left (y{\left (x \right )} \right )}, \quad - x e^{y{\left (x \right )}} - \sin{\left (x \right )} \cos{\left (y{\left (x \right )} \right )} = C_{1}\right )$$

Ejercicio 3 ejer2(a) libro


In [22]:
y=Function('y')(x)
Ecuacion=Eq((3*x**2-y**2)*y.diff(),2*x*y)
sol=dsolve(Ecuacion,y)
Ecuacion
#sol


Out[22]:
$$\left(3 x^{2} - y^{2}{\left (x \right )}\right) \frac{d}{d x} y{\left (x \right )} = 2 x y{\left (x \right )}$$

In [23]:
#multiplico por el factor integrante
y=Function('y')(x)
Ecuacion=Eq(y**(-4)*(3*x**2-y**2)*y.diff(),2*x*y**(-3))
sol=dsolve(Ecuacion,y)
Ecuacion
#sol


Out[23]:
$$\frac{\frac{d}{d x} y{\left (x \right )}}{y^{4}{\left (x \right )}} \left(3 x^{2} - y^{2}{\left (x \right )}\right) = \frac{2 x}{y^{3}{\left (x \right )}}$$

In [24]:
#corroboramos la solución
y=symbols('y')
equ=Eq(-x**2/y**3+1/y,c)
expr=-x**2/y**3+1/y
funx=diff(expr,x,1).simplify()
funy=diff(expr,y,1).simplify()
funx,funy


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-24-634ab159ff2c> in <module>()
      1 #corroboramos la solución
      2 y=symbols('y')
----> 3 equ=Eq(-x**2/y**3+1/y,c)
      4 expr=-x**2/y**3+1/y
      5 funx=diff(expr,x,1).simplify()

NameError: name 'c' is not defined

Ejercicio 3 ejer2(c) libro


In [ ]:
y=Function('y')(x)
Ecuacion=Eq(y+(x+3*x**3*y**4)*y.diff(),)
sol=dsolve(Ecuacion,y)
Ecuacion
#sol

In [ ]:

Ejercicio 3 ejer2(h) libro


In [ ]:
y=Function('y')(x)
Ecuacion=Eq(y+(2*x-y*exp(y))*y.diff(),)
sol=dsolve(Ecuacion,y)
Ecuacion,sol

Ejercicio 4 ejer2(a) libro


In [25]:
y=Function('y')(x)
Ecuacion=Eq(x*y.diff()-3*y,x**4)
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[25]:
$$\left ( x \frac{d}{d x} y{\left (x \right )} - 3 y{\left (x \right )} = x^{4}, \quad y{\left (x \right )} = x^{3} \left(C_{1} + x\right)\right )$$

Ejercicio 4 ejer2(c) libro


In [28]:
y=Function('y')(x)
Ecuacion=Eq((1+x**2)*y.diff()+2*x*y,cos(x)/sin(x))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[28]:
$$\left ( 2 x y{\left (x \right )} + \left(x^{2} + 1\right) \frac{d}{d x} y{\left (x \right )} = \frac{\cos{\left (x \right )}}{\sin{\left (x \right )}}, \quad y{\left (x \right )} = \frac{1}{x^{2} + 1} \left(C_{1} + \frac{1}{2} \log{\left (- \sin^{2}{\left (x \right )} \right )}\right)\right )$$

Ejercicio 4 ejer2(h) libro


In [30]:
y=Function('y')(x)
Ecuacion=Eq(y.diff()-2*x*y,6*x*exp(x**2))
sol=dsolve(Ecuacion,y)
Ecuacion,sol


Out[30]:
$$\left ( - 2 x y{\left (x \right )} + \frac{d}{d x} y{\left (x \right )} = 6 x e^{x^{2}}, \quad y{\left (x \right )} = \left(C_{1} + 3 x^{2}\right) e^{x^{2}}\right )$$

In [ ]:


In [ ]: